package models;

import play.data.validation.Constraints.*;
import play.db.ebean.Model;
import play.db.ebean.Model.Finder;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

import java.util.*;
 
public class User extends Model {
     
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
    public Long id;
    
    @Required
    @Column(name = "login", unique = true)
    @Max(15) @NotNull
    public String login;
     
    @Required
    @Column(name = "password")
    public String password;
    
    @Required
    public String phone;
    
    @Required
    public String mail;
    
    public static Finder<Long,User> find = new Finder<Long, User>(
			Long.class, User.class
			);

	static List<User> all() {
	    return find.all();	    
	}
	     
	public static List<User> findAll() {
	    return all();
	}
	     
	public static User findById(Long id) {
	    return find.byId(id);
	}
	
	public static User findByLogin(String login) {
	    return find.where().eq("login",login).findUnique();
	}
	
	public static void create(User user) {
		user.save();
	}
	
	public static void delete(Long id) {
		find.ref(id).delete();
	}
}